package edu.hnu.cloudflightserver.util;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class FileUtil {

	/**
	 * 获取类加载路径下某文件的输入流
	 * @param fileName
	 * @return
	 */
	public static InputStream getInputStreamAtClassPath(String fileName){
		return FileUtil.class.getClassLoader().getResourceAsStream(fileName);
	}
	
	
	/**
	 * 从类根目录加载文件并返回Properties
	 * @param fileName 文件名
	 * @return 发生异常返回null,正确读取返回Properties对象
	 */
	public static Properties getPropertiesAtClassPath(String fileName){
		Properties pro = new Properties();
		try {
			pro.load(getInputStreamAtClassPath(fileName));
			return pro;
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}
}
